package com.songcha.module_mine.ui.activity.teenager.mode

import android.os.Bundle
import android.widget.ImageView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.facade.annotation.Route
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import com.songcha.library_base.mvvm.base.BaseMvvmActivity
import com.songcha.library_base.mvvm.base.BaseRefreshMvvmActivity
import com.songcha.library_business.interfaces.IOnBookClickListener
import com.songcha.library_business.ui.adapter.BookListAdapter
import com.songcha.library_business.util.BusinessJumpUtil
import com.songcha.library_common.ui.dialog.CustomDialog
import com.songcha.library_common.util.JumpUtil
import com.songcha.library_common.util.TimeUtil
import com.songcha.module_mine.R
import com.songcha.module_mine.databinding.MineActivityTeenagerModeBinding
import com.songcha.module_mine.ui.activity.teenager.exit.ExitTeenagerModeActivity
import kotlin.system.exitProcess

/***
 * 青少年模式Activity
 */
@Route(path="/mine/TeenagerModeActivity")
class TeenagerModeActivity:BaseRefreshMvvmActivity<TeenagerModeViewModel,MineActivityTeenagerModeBinding>(),IOnBookClickListener {
    private var mAdapter:BookListAdapter?=null


    override fun getLayoutId(): Int {
        return R.layout.mine_activity_teenager_mode
    }

    override fun isImmerseStatusBar(): Boolean {
        return true
    }

    override fun initView(savedInstanceState: Bundle?) {
        super.initView(savedInstanceState)
        databinding.mineBtnExitTeenager.setOnClickListener {
            JumpUtil.toActivity(it.context, ExitTeenagerModeActivity::class.java)
        }

        /*val list= mutableListOf("","","","","")
        databinding.mineRcvTeenager.apply {
            layoutManager=LinearLayoutManager(context)
            mAdapter=BookListAdapter(list)
            adapter=mAdapter
        }*/

        val hour=TimeUtil.getCurrentHour()
        //cannot use app when in teenager mode and time between 22-8 hour
        if ((hour>=22 && hour<=23)  || (hour>=0 && hour<8)){
            val db=CustomDialog.Companion.Builder(this)
            db.setDialogMsg("青少年模式下22：00-8:00不能使用")
                .setCancelText("退出应用")
                .setConfirmText("关闭青少年模式")
                .setCancelOnTouchOutside(false)
                .setOnConfirmListener {
                   JumpUtil.toActivity(this,ExitTeenagerModeActivity::class.java)
                   false
                }
                .setOnCancelListener {
                    exitProcess(0)
                }
                .create().show()
        }
    }


    override fun initListData() {
       databinding.mineRcvTeenager.apply {
           layoutManager=LinearLayoutManager(context)
           mAdapter= BookListAdapter(viewModel.rlst.value!!,this@TeenagerModeActivity)
           adapter=mAdapter
       }
    }

    override fun getRefreshLayout(): SmartRefreshLayout {
       return databinding.mineTeenagerSrl
    }

    override fun getListAdapter(): RecyclerView.Adapter<BaseViewHolder>? {
        if(mAdapter==null) return null
        return mAdapter
    }

    override fun onGetData() {
        viewModel.getTeenagerBook()
    }

    override fun onBookClick(bookId: String,img: ImageView) {
        BusinessJumpUtil.toBookDetail(bookId)
    }

    override fun isNeedShowLoad(): Boolean {
        return true
    }

}